package com.pi.base.common;

import redis.clients.jedis.Jedis;

public class RedisUtils {
	
	private static final String jedisHost="r-bp1762333dc03c54.redis.rds.aliyuncs.com";
	private static final int jedisPort=6379;
	private static final String jedisPwd="aAroot123";
	
	public static void main(String[] args) {
		System.out.println(getAccessToken());
		System.out.println(getTicketToken());
	}
	
	public static String getTicketToken(){
		return getJedisValue("ap_ticket_token");
	}
	
	public static String getAccessToken(){
		return getJedisValue("ap_access_token");
	}
	
	private static String getJedisValue(String key) {
		String value = "";
		try {
			Jedis jedis = new Jedis(jedisHost, jedisPort);
			jedis.auth(jedisPwd);//鉴权信息
	
			for(int i = 0; i < 30 && jedis.exists("pa_token"); i++){
				Thread.sleep(100);
			}
			
			value = jedis.get(key);
			
			jedis.quit();
			jedis.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return value;
	}
	
}
